package demo.dcs;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class XUIDGenerateTraceId implements GenerateTraceId{
	private static Logger logger = LoggerFactory.getLogger(XUIDGenerateTraceId.class);

	@Override
	public String generateTraceId() {
		
		return generateXUid();
	}

	@Override
	public String generateSpanId() {

		return generateXUid();
	}

	private String generateXUid(){
		Long startTime = System.currentTimeMillis();
		String id = XUID.getUniqueId();
		Long endTime = System.currentTimeMillis();
		if(endTime - startTime > 5){
			logger.warn("xdcs XUIDGenerateTraceId cost: " + (endTime - startTime) + "ms");
		}

		return id;
	}
	
	public static void main(String[] args) {
		System.out.println(XUID.getUniqueId());
	}



}
